#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3e5 + 5;
const int MOD = 998244353;
mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
int head[N];
int ver[N], Next[N], tot;
ll ans[N], cnt[N], dep[N];
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
void init() {
  rep(i, 1, n) head[i] = ans[i] = cnt[i] = 0;
  tot = 0;
}
ll bfs() {
  dep[1] = 1;
  ans[1] = 1;
  cnt[1] = 1;
  queue<int> q;
  q.push(1);
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = Next[i]) {
      int v = ver[i];
      q.push(v);
      dep[v] = dep[u] + 1;
      ans[v] = dep[u] == 1 ? 1 : (cnt[dep[u]] - ans[u] + MOD) % MOD;
      cnt[dep[v]] = (cnt[dep[v]] + ans[v]) % MOD;
    }
  }
  ll res = 0;
  rep(i, 1, n) res = (res + ans[i]) % MOD;
  return res;
}
void solve() {
  cin >> n;
  init();
  rep(i, 2, n) {
    int x;
    cin >> x;
    add(x, i);
  }
  cout << bfs() << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}